import { ReactNode, Suspense, lazy } from "react"
import { IRouteType } from "@/models/common"
import Loading from "@/components/loading"

export const lazyLoad = (children: ReactNode): ReactNode => {
  return <Suspense fallback={< Loading tip="loading" />}>
    {children}
  </Suspense>
}

// 引入组件使用路由懒加载
const LayoutFC = lazy(() => import(/* webpackChunkName: "layout" */ "@/components/layout/layout"))
const IndexFC = lazy(() => import(/* webpackChunkName: "index" */ "@/document/pages/index/index"))
const ManageBackGroundLayoutFC = lazy(() => import(/* webpackChunkName: "managebackgroundlayout" */ "@/document/pages/managebackground/components/layout/layout"))
const ManageBackGroundAdminSettingPage = lazy(() => import(/* webpackChunkName: "managebackgroundadminsetting" */ "@/document/pages/managebackground/adminsetting/adminsetting"))
const ManageBackGroundDictSettingPage = lazy(() => import(/* webpackChunkName: "managebackgroundadmindictsetting" */ "@/document/pages/managebackground/dictsetting/dictsetting"))
const ManageBackGroundKnowledgeBaseAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundknowledgebaseadmin" */ "@/document/pages/managebackground/knowledgebaseadmin/knowledgebaseadmin"))
const ManageBackGroundRoleAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundroleadmin" */ "@/document/pages/managebackground/roleadmin/roleadmin"))
const ManageBackGroundMemberAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundmemberadmin" */ "@/document/pages/managebackground/memberadmin/memberadmin"))
const ManageBackGroundFileAttributeAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundfileattributeadmin" */ "@/document/pages/managebackground/fileattributeadmin/fileattributeadmin"))
const ManageBackGroundSystemInfoPage = lazy(() => import(/* webpackChunkName: "managebackgroundsysteminfo" */ "@/document/pages/managebackground/systeminfo/systeminfo"))
const ManageBackGroundStoragePoolPage = lazy(() => import(/* webpackChunkName: "managebackgroundstoragepool" */ "@/document/pages/managebackground/storagepool/storagepool"))
const ManageBackGroundBackupSchedulePage = lazy(() => import(/* webpackChunkName: "managebackgroundbackupschedule" */ "@/document/pages/managebackground/backupschedule/backupschedule"))
const ManageBackGroundFileOwnerSwitchPage = lazy(() => import(/* webpackChunkName: "managebackgroundfileownerswitch" */ "@/document/pages/managebackground/fileownerswitch/fileownerswitch"))
const ManageBackGroundLogAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundlogadmin" */ "@/document/pages/managebackground/logadmin/logadmin"))
const ManageBackGroundFrmShortcutAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundfrmshortcutadmin" */ "@/document/pages/managebackground/frmshortcutadmin/frmshortcutadmin"))
const ManageBackGroundFileClassAdminPage = lazy(() => import(/* webpackChunkName: "managebackgroundfileclassadmin" */ "@/document/pages/managebackground/fileclassadmin/fileclassadmin"))
const NotFoundPage = lazy(() => import(/* webpackChunkName: "notfound" */ "@/document/pages/notfound/notfound"))

const routes: IRouteType[] = [
  {
    path: '/',
    meta: {
      title: '企业文档管理平台',
      needLogin: true,
      isMenu: false
    },
    element: lazyLoad(<LayoutFC />),
    childrens: [
      {
        index: true,
        element: lazyLoad(<ManageBackGroundLayoutFC />),
      },
      {
        path: '/index',
        meta: {
          title: '管理后台',
          needLogin: true,
          isMenu: false
        },
        element: lazyLoad(<IndexFC />),
      },
      {
        path: '/managebackground',
        meta: {
          title: '管理后台',
          needLogin: true,
          isMenu: false
        },
        element: lazyLoad(<ManageBackGroundLayoutFC />),
        childrens: [
          {
            path: 'adminsetting',
            meta: {
              title: '系统设置',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundAdminSettingPage />),
          },
          {
            path: 'dictsetting',
            meta: {
              title: '数据字典管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundDictSettingPage />),
          },
          {
            path: 'knowledgebaseadmin',
            meta: {
              title: '知识库管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundKnowledgeBaseAdminPage />),
          },
          {
            path: 'roleadmin',
            meta: {
              title: '角色管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundRoleAdminPage />),
          },
          {
            path: 'memberadmin',
            meta: {
              title: '成员管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundMemberAdminPage />),
          },
          {
            path: 'fileattributeadmin',
            meta: {
              title: '文件属性管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundFileAttributeAdminPage />),
          },
          {
            path: 'systeminfo',
            meta: {
              title: '系统信息',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundSystemInfoPage />),
          },
          {
            path: 'storagepool',
            meta: {
              title: '储存池',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundStoragePoolPage />),
          },
          {
            path: 'backupschedule',
            meta: {
              title: '备份',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundBackupSchedulePage />),
          },
          {
            path: 'fileownerswitch',
            meta: {
              title: '文件所有者变更',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundFileOwnerSwitchPage />),
          },
          {
            path: 'logadmin',
            meta: {
              title: '操作日志',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundLogAdminPage />),
          },
          {
            path: 'frmshortcutadmin',
            meta: {
              title: '快捷方式管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundFrmShortcutAdminPage />),
          },
          {
            path: 'fileclassadmin',
            meta: {
              title: '文件分类管理',
              needLogin: true,
              isMenu: false
            },
            element: lazyLoad(<ManageBackGroundFileClassAdminPage />),
          },
        ]
      }
    ]
  },
  {
    path: "/notfound/:type",
    meta: {
      title: '企业文档管理平台',
      needLogin: false,
      isMenu: false
    },
    element: lazyLoad(<NotFoundPage />),
  },
  {
    path: "*",
    meta: {
      title: '404',
      needLogin: false,
      isMenu: false
    },
    element: lazyLoad(<NotFoundPage />),
  },
];



export default routes
